from django.db import models
from .base import BaseModel

class Character(BaseModel):
    """角色模型"""
    # 基础信息
    name = models.CharField(max_length=50, verbose_name='角色名称')
    description = models.TextField(blank=True, verbose_name='角色描述')
    
    # 五维属性
    constitution = models.IntegerField(default=10, verbose_name='体质')
    strength = models.IntegerField(default=10, verbose_name='力量')
    spirit = models.IntegerField(default=10, verbose_name='精神')
    intelligence = models.IntegerField(default=10, verbose_name='智力')
    luck = models.IntegerField(default=10, verbose_name='幸运')
    
    # 战斗基础属性
    max_hp = models.IntegerField(verbose_name='最大生命值')
    current_hp = models.IntegerField(verbose_name='当前生命值')
    max_mp = models.IntegerField(verbose_name='最大法力值')
    current_mp = models.IntegerField(verbose_name='当前法力值')
    
    # 防御属性
    physical_armor = models.IntegerField(default=0, verbose_name='物理护甲')
    current_physical_armor = models.IntegerField(default=0, verbose_name='当前物理护甲')
    magic_armor = models.IntegerField(default=0, verbose_name='魔法护甲')
    current_magic_armor = models.IntegerField(default=0, verbose_name='当前魔法护甲')
    damage_reduction = models.IntegerField(default=0, verbose_name='固定值减伤')
    current_damage_reduction = models.IntegerField(default=0, verbose_name='当前固定值减伤')
    damage_reduction_percentage = models.FloatField(default=0, verbose_name='百分比减伤')
    current_damage_reduction_percentage = models.FloatField(default=0, verbose_name='当前百分比减伤')
    shield_value = models.IntegerField(default=0, verbose_name='护盾值')
    current_shield_value = models.IntegerField(default=0, verbose_name='当前护盾值')
    block_value = models.IntegerField(default=0, verbose_name='格挡值')
    current_block_value = models.IntegerField(default=0, verbose_name='当前格挡值')
    dodge_rate = models.FloatField(default=0, verbose_name='闪避率')
    current_dodge_rate = models.FloatField(default=0, verbose_name='当前闪避率')
    
    # 攻击属性
    damage_bonus = models.IntegerField(default=0, verbose_name='固定值增伤')
    current_damage_bonus = models.IntegerField(default=0, verbose_name='当前固定值增伤')
    damage_bonus_percentage = models.FloatField(default=0, verbose_name='百分比增伤')
    current_damage_bonus_percentage = models.FloatField(default=0, verbose_name='当前百分比增伤')
    crit_rate = models.FloatField(default=0.05, verbose_name='暴击率')
    current_crit_rate = models.FloatField(default=0.05, verbose_name='当前暴击率')
    crit_damage = models.FloatField(default=1.5, verbose_name='暴击伤害')
    current_crit_damage = models.FloatField(default=1.5, verbose_name='当前暴击伤害')
    life_steal = models.FloatField(default=0, verbose_name='吸血率')
    current_life_steal = models.FloatField(default=0, verbose_name='当前吸血率')
    armor_penetration = models.IntegerField(default=0, verbose_name='护甲穿透')
    current_armor_penetration = models.IntegerField(default=0, verbose_name='当前护甲穿透')

    # 治疗属性
    healing_bonus = models.IntegerField(default=0, verbose_name='固定值治疗增幅')
    current_healing_bonus = models.IntegerField(default=0, verbose_name='当前固定值治疗增幅')
    healing_bonus_percentage = models.FloatField(default=0, verbose_name='百分比治疗增幅')
    current_healing_bonus_percentage = models.FloatField(default=0, verbose_name='当前百分比治疗增幅')
    hp_regen = models.FloatField(default=0, verbose_name='生命值回复')
    current_hp_regen = models.FloatField(default=0, verbose_name='当前生命值回复')
    
    # 移动属性
    movement_speed = models.IntegerField(default=30, verbose_name='移动速度')
    current_movement_speed = models.IntegerField(default=30, verbose_name='当前移动速度')
    attack_range = models.IntegerField(default=1, verbose_name='攻击距离')
    current_attack_range = models.IntegerField(default=1, verbose_name='当前攻击距离')
    flying_height = models.IntegerField(default=0, verbose_name='飞行高度')
    current_flying_height = models.IntegerField(default=0, verbose_name='当前飞行高度')
    
    # 战斗相关
    initiative = models.IntegerField(default=0, verbose_name='先攻值')
    action_points = models.IntegerField(default=1, verbose_name='行动点数')
    
    # 新增：角色所有者
    owner = models.ForeignKey(
        'accounts.User',
        on_delete=models.CASCADE,
        related_name='characters',
        verbose_name='角色所有者'
    )
    
    # 新增：是否为模板
    is_template = models.BooleanField(default=False, verbose_name='是否为模板')
    
    # 新增：如果是从模板创建，记录模板来源
    template = models.ForeignKey(
        'self',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='instances',
        verbose_name='模板来源'
    )
    
    class Meta:
        verbose_name = '角色'
        verbose_name_plural = '角色' 